//
//  StatusesRepostCell.swift
//  SinaMicroBlog
//
//  Created by wxy on 15/9/9.
//  Copyright © 2015年 wxy. All rights reserved.
//

import UIKit

class StatusesRepostCell: StatusesCell {

    // 重写父类 微博数据视图模型
    // 不需要super 父类的didSet 仍然能够正常执行 只需要设置子类的控件内容
    override var statusesViewModel: StatusesViewModel? {
        
        didSet {
            repostLabel.text = statusesViewModel?.repostText
        }
    }
    
    override func setUpUI() {
        
        // 必须执行父类的方法
        super.setUpUI()
        
        // 添加控件
        contentView.insertSubview(backgroundButton, belowSubview: pictureView)
        contentView.insertSubview(repostLabel, aboveSubview: backgroundButton)
        
        // 设置布局
        // 1> 背景按钮
        backgroundButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -StatusesCellMargin, y: StatusesCellMargin))
        backgroundButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        // 2> 转发文字
        repostLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backgroundButton, size: nil, offset: CGPoint(x: StatusesCellMargin, y: StatusesCellMargin))
        
        // 3> 转发微博配图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: repostLabel, size: CGSize(width: StatusesPictureMaxWidth, height: StatusesPictureMaxWidth), offset: CGPoint(x: 0, y: StatusesPictureItemMargin))
        
        // 记录配图视图约束
        pictureViewWidthConsttraint = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightConstraint = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureViewTopConstraint = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)

    }
    
    // MARK: - 懒加载控件
    private lazy var backgroundButton: UIButton = {
        
        let backBtn = UIButton()
        
        backBtn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        return backBtn
    }()
    
    private lazy var repostLabel: UILabel = UILabel(title: "转发微博", color: UIColor.darkGrayColor(), fontSize: 14, layoutWidth: UIScreen.mainScreen().bounds.width - 2 * StatusesCellMargin)
}
